﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calendar
{
    internal class CalculateCalendar
    {

        //计算一个月有多少天
        public int DayNumOfMonth(int year, int month)
        {
            int monthMax = 0;
            //31天的情况
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
            {
                monthMax = 31;
            }
            //30天的情况
            if (month == 4 || month == 6 || month == 9 || month == 11)
            {
                monthMax = 30;
            }
            //2月份 分闰年与非闰年的情况
            if (month == 2)
            {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
                {//r闰年
                    monthMax = 29;
                }
                else
                {//非闰年
                    monthMax = 28;
                }
            }
            return monthMax;
        }

        //判断今天是周几
        public int Date(int year, int month, int day)
        {

            int week;
            if (month == 1 || month == 2)
            {
                month += 12;
                year--;
            }
            week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400 + 1) % 7;
            return week;// 0-6 表示周日到周六
        }
    }
}
